/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.geftu.view;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import org.apache.commons.io.IOUtils;

public class Principal {

    public static void main(String[] args) {

        JFrame frame = new JFrame();
        frame.setLayout(new FlowLayout());
        frame.setSize(800, 600);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);

        JButton button = new JButton("Chamar o Seletor");
        frame.add(button);

        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                JFileChooser fc = new JFileChooser();
                fc.setDialogTitle("Salvar arquivos");
                fc.setDialogType(JFileChooser.SAVE_DIALOG);
                fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
                fc.setMultiSelectionEnabled(true);
                File dir = new File("Lixin1");
                File[] listar = dir.listFiles();
                FileInputStream origem;
                FileOutputStream destino;
                fc.setSelectedFiles(listar);
                String caminho = "Lixin2";
                int i = fc.showSaveDialog(null);
                if (i == JFileChooser.APPROVE_OPTION) {
                    File[] listFiles = fc.getSelectedFiles();
                    for (int x = 0; x < listFiles.length; x++) {
                        try {
                            origem = new FileInputStream(listFiles[x].getAbsolutePath());
                            destino = new FileOutputStream(caminho + listFiles[x].getName());
                            {
                            }
                            IOUtils.copy(origem, destino);

                            origem.close();
                            destino.close();
                        } catch (IOException fnf) {
                            fnf.getCause();
                        }
                    }

                } else {

                }

            }
        });

        frame.setVisible(true);
        JOptionPane.showMessageDialog(null, "teste1");
    }
}
